package wifiunion.com.notice.presenter;

import android.content.Context;
import android.graphics.Bitmap;

import wifiunion.com.notice.BaseImageUploadPresenter;
import wifiunion.com.notice.ConfigureContact;
import wifiunion.com.notice.Constants;
import wifiunion.com.notice.model.UploadImgModel;
import wifiunion.com.notice.utils.SharedPreferencesUtils;

/**
 * Created by Administrator on 2016/12/1.
 */

public class UploadImgPresenter implements BaseImageUploadPresenter, ConfigureContact.Callback {

    private ConfigureContact.View mView;
    private Context mContext;
    private UploadImgModel mModel;


    private Bitmap mBmp;

    public UploadImgPresenter(Context context, ConfigureContact.View view) {
        mView = view;
        mContext = context;
        mModel = new UploadImgModel();
    }

    @Override
    public void onSuccess(Object data) {

        if (mBmp != null) {
            mBmp.recycle();
            mBmp = null;
        }

        mView.onImgUploadSuccess((String) data);
    }

    @Override
    public void onServerFailed(Object errorObj) {
        if (mBmp != null) {
            mBmp.recycle();
            mBmp = null;
        }
        mView.onError((String) errorObj);
    }

    @Override
    public void onNetFailed() {
        if (mBmp != null) {
            mBmp.recycle();
            mBmp = null;
        }


        mView.onError("网络异常");
    }


    @Override
    public void start(Bitmap bmp) {
        mBmp = bmp;
        mModel.loadData(SharedPreferencesUtils.getSharedPreferences(Constants.CONFIG_AUTHTOKEN, mContext), bmp, this);
    }
}
